package com.qing.study.controller;

import com.qing.study.comm.Result;
import com.qing.study.service.SendSmsService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
//支持跨域
@CrossOrigin
@Api(tags = "阿里云短信验证码服务")
@RequestMapping("sms")
public class SendSmsController {
    @Resource
    private SendSmsService sendSmsService;

    @ApiOperation("发送短信")
    @GetMapping("sendSms")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "phoneNum", value = "手机号", dataType = "String", required = true)})
    public Result sendSms(String phoneNum) throws Exception {
        return sendSmsService.sendSms(phoneNum);
    }

    @ApiOperation("通过短信验证码验证登录")
    @GetMapping("verifyCodeForLogin")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "phoneNum", value = "手机号", dataType = "String", required = true),
            @ApiImplicitParam(name = "code", value = "短信验证码", dataType = "String", required = true)}
    )
    public Result verifyCodeForLogin(String phoneNum,String code) throws Exception {
        return sendSmsService.verifyCodeForLogin(phoneNum,code);
    }
}
